#include "../afwwin.h"

#include <Richedit.h>  // #defines MSFTEDIT_CLASS and RICHEDIT_CLASS

using namespace one_rag::impl;
using namespace one_rag;

Win32RichEditCtrl::Win32RichEditCtrl()
{
  //ctor
}

Win32RichEditCtrl::~Win32RichEditCtrl()
{
  //dtor
}

HWND CreateRichEdit(
    HWND hwndOwner,        // Dialog box handle.
    int x, int y,          // Location.
    int width, int height)       // Application or DLL instance.
{
  static HMODULE msft_mod = LoadLibrary(TEXT("Msftedit.dll"));


  return CreateWindowEx(0, TEXT("RICHEDIT50W"), NULL,
      ES_READONLY | ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
      x, y, width, height,
      hwndOwner, NULL, msft_mod, NULL);
}

HWND Win32RichEditCtrl::Create(Window& parent,int x,int y,int w,int h)
{
  if(w<0)
  {
    SIZE sz=parent.GetClientSize();
    w = sz.cx;
    h = sz.cy;
  }

  return _wnd = CreateRichEdit(parent,x,y,w,h);
}


void Win32RichEditCtrl::AddText(LPCTSTR text)
{
  #ifdef UNICODE
  int cp = 1200;
  #else
  int cp = CP_ACP;
  #endif
  SETTEXTEX ste = {ST_SELECTION,cp};
  SendMessage(_wnd,EM_SETTEXTEX,(WPARAM)&ste,(LPARAM)text);
}
